import unittest, requests

from lx.A3mall.yj import yj


class A3mall(unittest.TestCase):
    def setUp(self) -> None:
        print("开始执行")
        yj().Log()
    def tearDown(self) -> None:
        print("执行结束")

    '''登录'''
    token = None

    def test_A3mall_01(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": "15512945419", "password": "123456"}
        r_login = requests.post(url=url, json=json)
        print(r_login.json())
        A3mall.token = 'Bearer '+r_login.json()['data']['token']
        print(A3mall.token)

    '''秒杀商品列表'''
    spid = None

    def test_A3mall_02(self):
        url = 'http://10.59.9.14:7003/api/second?page=1&type=0&sort=1'
        r_second = requests.get(url=url)
        print(r_second.json())
        A3mall.spid = r_second.json()['data']['list'][0]['id']
        print(A3mall.spid)

    goods_id = None
    '''商品详情页'''

    def test_A3mall_03(self):
        url = f'http://10.59.9.14:7003/api/second/view?id={A3mall.spid}'
        r_view = requests.get(url=url)
        print(r_view.json())
        A3mall.goods_id = r_view.json()['data']['goods']['goods_id']
        print(A3mall.goods_id)

    '''创建订单'''

    def test_A3mall_04(self):
        url = f'http://10.59.9.14:7003/api/order/confirm?id={A3mall.spid}&type=second&sku_id=&num=1&shipping_type=1'
        headers={'Auth-Token':A3mall.token}
        r_view = requests.get(url=url,headers=headers)
        print(r_view.json())

    '''提交订单'''

    def test_A3mall_05(self):
        url = 'http://10.59.9.14:7003/api/order/create'
        headers = {'Auth-Token': A3mall.token}
        json = {"id":A3mall.spid,"type":"second","address_id":11,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","source":1,"num":"1"}
        r_create = requests.post(url=url, json=json ,headers=headers)
        print(r_create.json())


if __name__ == '__main__':
    unittest.main()
